package demo7;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;


@SuppressWarnings({"all"})
public class Test {
    public static void main(String[] args) {
        ArrayList<employee> employees = new ArrayList<>();
        employees.add(new employee("tom",20000,new MyDate(1000,1,1)));
        employees.add(new employee("jack",30000,new MyDate(2000,3,5)));
        employees.add(new employee("jack",30000,new MyDate(2000,3,8)));


        System.out.println(employees);

        //下面的这个就是一个匿名内部类，依据此进行排序
        employees.sort(new Comparator<employee>() {
            @Override
            public int compare(employee o1, employee o2) {
                //先对于这个参数传入的实参进行验证
                if(!(o1 instanceof employee & o2 instanceof employee))
                {
                    System.out.println("类型不匹配~~");
                    return 0;
                }

                int i=o1.getName().compareTo(o2.getName());
                if(i!=0){
                    return i;
                }

                return o1.getBirthday().compareTo(o2.getBirthday());
            }
        });

        System.out.println("排序之后的结果");
        System.out.println(employees);
    }
}

class MyDate implements Comparable<MyDate>{
    private int year;
    private int month;
    private int day;

    @Override
    public int compareTo(MyDate o) {
        int yearMinus=year-o.getYear();
        if(yearMinus!=0){
            return yearMinus;
        }

        int monthMinus=month-o.getMonth();
        if(monthMinus!=0){
            return monthMinus;
        }

        return day-o.getDay();
    }

    public MyDate(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    @Override
    public String toString() {
        return "MyDate{" +
                "year=" + year +
                ", month=" + month +
                ", day=" + day +
                '}';
    }
}


class employee{
    private String name;
    private double salary;
    private MyDate birthday;

    @Override
    public String toString() {
        return "\nemployee{" +
                "name='" + name + '\'' +
                ", birthday=" + birthday +
                ", salary=" + salary +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public MyDate getBirthday() {
        return birthday;
    }

    public void setBirthday(MyDate birthday) {
        this.birthday = birthday;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public employee(String name, double salary, MyDate birthday) {
        this.name = name;
        this.salary = salary;
        this.birthday = birthday;
    }
}
